import pymysql

# Insert data into the tb_spu table
spu_insert_query = """
INSERT INTO `tb_spu` (id, create_time, update_time, name, sales, comments, brand_id, category1_id, category2_id, category3_id, desc_detail, desc_pack, desc_service) VALUES 
(1, '2018-04-10 10:00:00', '2018-04-10 10:00:00', 'Apple MacBook Pro 13.3英寸笔记本', 0, 0, 1, 1, 2, 3, '详细描述', '包装说明', '售后服务'),
(2, '2018-04-10 10:00:00', '2018-04-10 10:00:00', 'Apple iPhone 8 Plus (A1864)', 0, 0, 1, 1, 2, 3, '详细描述', '包装说明', '售后服务'),
(3, '2018-04-10 10:00:00', '2018-04-10 10:00:00', '华为 HUAWEI P10 Plus', 0, 0, 2, 1, 2, 3, '详细描述', '包装说明', '售后服务');
"""

# Insert data into the tb_sku table
sku_insert_query = """
INSERT INTO `tb_sku` VALUES 
(1,'2018-04-11 17:28:21.804713','2018-04-25 11:09:04.532866','Apple MacBook Pro 13.3英寸笔记本 银色','【全新2017款】MacBook Pro,一身才华，一触，即发 了解【黑五返场特惠】 更多产品请点击【美多官方Apple旗舰店】',11388.00,10350.00,13388.00,5,5,1,1,157,1,'group1/M00/00/02/CtM3BVrPB4GAWkTlAAGuN6wB9fU4220429'),
(2,'2018-04-12 06:53:54.575306','2018-04-23 11:44:03.825103','Apple MacBook Pro 13.3英寸笔记本 深灰色','【全新2017款】MacBook Pro,一身才华，一触，即发 了解【黑五返场特惠】 更多产品请点击【美多官方Apple旗舰店】',11398.00,10388.00,13398.00,0,1,0,1,157,1,'group1/M00/00/02/CtM3BVrPCAOAIKRBAAGvaeRBMfc0463515'),
(3,'2018-04-14 02:14:04.599169','2018-04-14 17:26:54.041015','Apple iPhone 8 Plus (A1864) 64GB 金色 移动联通电信4G手机','选【移动优惠购】新机配新卡，198优质靓号，流量不限量！',6499.00,6300.00,6598.00,10,0,0,1,115,2,'group1/M00/00/02/CtM3BVrRZCqAUxp9AAFti6upbx41220032'),
(4,'2018-04-14 02:20:33.355996','2018-04-14 17:27:12.736139','Apple iPhone 8 Plus (A1864) 256GB 金色 移动联通电信4G手机','选【移动优惠购】新机配新卡，198优质靓号，流量不限量！',7988.00,7888.00,8088.00,8,2,0,1,115,2,'group1/M00/00/02/CtM3BVrRZa6ANO_sAAFti6upbx40753757'),
(5,'2018-04-14 02:45:23.341909','2018-04-14 17:27:17.181609','Apple iPhone 8 Plus (A1864) 64GB 深空灰色 移动联通电信4G手机','选【移动优惠购】新机配新卡，198优质靓号，流量不限量！',6688.00,6588.00,6788.00,10,0,0,1,115,2,'group1/M00/00/02/CtM3BVrRa8iAZdz1AAFZsBqChgk2188464'),
(6,'2018-04-14 02:49:40.912682','2018-04-25 11:09:35.936530','Apple iPhone 8 Plus (A1864) 256GB 深空灰色 移动联通电信4G手机','选【移动优惠购】新机配新卡，198优质靓号，流量不限量！',7988.00,7888.00,7988.00,0,5,1,1,115,2,'group1/M00/00/02/CtM3BVrRbI2ARekNAAFZsBqChgk3141998'),
(7,'2018-04-14 02:55:11.172604','2018-04-14 17:27:28.772353','Apple iPhone 8 Plus (A1864) 64GB 银色 移动联通电信4G手机','选【移动优惠购】新机配新卡，198优质靓号，流量不限量！',6688.00,6588.00,6788.00,3,0,0,1,115,2,'group1/M00/00/02/CtM3BVrRbh2AX3JVAAFvJD02RWs4638828'),
(8,'2018-04-14 02:56:17.331169','2018-04-14 17:27:34.536772','Apple iPhone 8 Plus (A1864) 256GB 银色 移动联通电信4G手机','选【移动优惠购】新机配新卡，198优质靓号，流量不限量！',7988.00,7888.00,7988.00,9,1,0,1,115,2,'group1/M00/00/02/CtM3BVrRbjSAazeSAAFvJD02RWs2636429'),
(9,'2018-04-14 03:09:00.909709','2018-04-14 17:27:40.624770','华为 HUAWEI P10 Plus 6GB+64GB 钻雕金 移动联通电信4G手机 双卡双待','wifi双天线设计！徕卡人像摄影！P10徕卡双摄拍照，低至2988元！',3388.00,3288.00,3388.00,4,0,0,1,115,3,'group1/M00/00/02/CtM3BVrRcUeAHp9pAARfIK95am88523545'),
(10,'2018-04-14 03:13:40.226704','2018-04-25 11:06:55.087206','华为 HUAWEI P10 Plus 6GB+128GB 钻雕金 移动联通电信4G手机 双卡双待','wifi双天线设计！徕卡人像摄影！P10徕卡双摄拍照，低至2988元！',3788.00,3588.00,3888.00,3,0,5,1,115,3,'group1/M00/00/02/CtM3BVrRchWAMc8rAARfIK95am88158618'),
(11,'2018-04-14 03:16:27.620102','2018-04-25 10:56:51.267674','华为 HUAWEI P10 Plus 6GB+128GB 钻雕蓝 移动联通电信4G手机 双卡双待','wifi双天线设计！徕卡人像摄影！P10徕卡双摄拍照，低至2988元！',3788.00,3588.00,3888.00,5,0,2,1,115,3,'group1/M00/00/02/CtM3BVrRdG6AYdapAAcPaeOqMpA1594598'),
(12,'2018-04-14 03:17:25.671905','2018-04-14 17:28:06.649098','华为 HUAWEI P10 Plus 6GB+64GB 钻雕蓝 移动联通电信4G手机 双卡双待','wifi双天线设计！徕卡人像摄影！P10徕卡双摄拍照，低至2988元！',3388.00,3288.00,3488.00,5,0,0,1,115,3,'group1/M00/00/02/CtM3BVrRdICAO_CRAAcPaeOqMpA2024091'),
(13,'2018-04-14 03:18:04.588296','2018-04-14 17:28:23.886231','华为 HUAWEI P10 Plus 6GB+64GB 玫瑰金 移动联通电信4G手机 双卡双待','wifi双天线设计！徕卡人像摄影！P10徕卡双摄拍照，低至2988元！',3388.00,3288.00,3488.00,5,0,0,1,115,3,'group1/M00/00/02/CtM3BVrRdLGARgBAAAVslh9vkK00474545'),
(14,'2018-04-14 03:19:03.691772','2018-04-25 11:10:51.316291','华为 HUAWEI P10 Plus 6GB+128GB 玫瑰金 移动联通电信4G手机 双卡双待','wifi双天线设计！徕卡人像摄影！P10徕卡双摄拍照，低至2988元！',3788.00,3588.00,3888.00,0,4,1,1,115,3,'group1/M00/00/02/CtM3BVrRdMSAaDUtAAVslh9vkK04466364'),
(15,'2018-04-14 03:20:00.777150','2018-04-14 17:28:16.738212','华为 HUAWEI P10 Plus 6GB+64GB 曜石黑 移动联通电信4G手机 双卡双待','wifi双天线设计！徕卡人像摄影！P10徕卡双摄拍照，低至2988元！',3388.00,3288.00,3488.00,3,2,0,1,115,3,'group1/M00/00/02/CtM3BVrRdOiAUBFXAAYJrpessGQ2842711'),
(16,'2018-04-14 03:20:36.855901','2018-04-26 10:47:07.236432','华为 HUAWEI P10 Plus 6GB+128GB 曜石黑 移动联通电信4G手机 双卡双待','666 wifi双天线设计！徕卡人像摄影！P10徕卡双摄拍照，低至2988元！',3788.00,3588.00,3888.00,5,0,0,1,115,3,'group1/M00/00/02/CtM3BVrRdPeAXNDMAAYJrpessGQ9777651');
"""

try:
    with pymysql.connect(
        host='172.19.251.204',
        user='meiduo_user',
        password='123456',
        port=3306,
        database='meiduo_mall'
    ) as connection:
        with connection.cursor() as cursor:
            # Insert data into the tb_spu table first
            cursor.execute(spu_insert_query)
            print("Data inserted into the tb_spu table successfully")
            # Commit the transaction
            connection.commit()

            # Then insert data into the tb_sku table
            cursor.execute(sku_insert_query)
            print("Data inserted into the tb_sku table successfully")
            # Commit the transaction
            connection.commit()
except pymysql.Error as err:
    print(f"An error occurred while inserting data: {err}")
    # Roll back the transaction in case of an error
    if 'connection' in locals() and connection.open:
        connection.rollback()